﻿#include <iostream>
#include <thread>
#include <atomic>

std::atomic<bool> ready(false);

void waitingThread() {
    std::cout << "Waiting for signal...\n";
    while (!ready.load()) {
        std::this_thread::yield(); // 暂时让出CPU
    }
    std::cout << "Received signal, continuing work.\n";
}

int main() {
    std::thread t(waitingThread);

    std::this_thread::sleep_for(std::chrono::seconds(2)); // 模拟其他工作
    ready.store(true); // 发信号
    t.join();
    return 0;
}
